package com.fs.controller.vo.user;

import com.fs.service.bo.user.BoRoleInfo;
import com.fs.service.bo.user.BoUserInfo;
import com.fs.service.bo.user.BoUserInfoWithRole;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class RespUserWithRole extends RespUser {
    private List<String> roles = new ArrayList<>();

    public void addRole(String roleName) {
        roles.add(roleName);
    }

    public RespUserWithRole(BoUserInfo user) {
        super(user);
    }

    public RespUserWithRole(BoUserInfoWithRole user){
        super(user);
        setRoles(user.getRoles().stream().map(BoRoleInfo::getName).collect(Collectors.toList()));
    }
}
